package com.example.word.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.word.annotation.OptLog;
import com.example.word.dto.CompRecordDTO;
import com.example.word.dto.TemplateDetailDTO;
import com.example.word.dto.TemplateRecordDTO;
import com.example.word.service.CompRecordService;
import com.example.word.util.UserUtils;
import com.example.word.vo.ConditionVO;
import com.example.word.vo.PageResult;
import com.example.word.vo.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static com.example.word.constant.OptTypeConst.REMOVE;

/**
 * 对比历史记录
 * @author yuwen
 * @date 2023/5/5
 */
@Api(tags = "对比历史记录模块")
@RestController
public class CompRecordController {
    @Autowired
    private CompRecordService compRecordService;

    @ApiOperation(value = "获取学生对比历史记录")
    @GetMapping("/users/getUserRecords")
    public Result<PageResult<CompRecordDTO>> getUserRecordsByUId(ConditionVO condition){
        return Result.ok(compRecordService.getUserRecordsByUId(condition));
    }
    @ApiOperation(value = "获取教师模板对比历史记录个数")
    @GetMapping("/users/getRecordsCountById")
    public Result<PageResult<TemplateRecordDTO>> getRecordsCountById(ConditionVO condition){
        return Result.ok(compRecordService.getRecordsCountById(condition));
    }
    @ApiOperation(value = "通过模板id获取对比详情")
    @GetMapping("/users/getDetailById")
    public Result<PageResult<TemplateDetailDTO>> getDetailById(@RequestParam("tmpId") Integer id,ConditionVO condition){
        return Result.ok(compRecordService.getDetailById(id,condition));
    }

    @OptLog(optType = REMOVE)
    @ApiOperation(value = "删除历史记录")
    @GetMapping("/users/deleteUserRecord")
    public Result<?> deleteUserRecordsById(@RequestBody List<Integer> recordId){
        compRecordService.removeByIds(recordId);
        return Result.ok();
    }

}
